package com.xyb.controller;

import com.xyb.entity.UserInfo;
import com.xyb.service.LoginService;
import com.xyb.utils.RegUtils;
import com.xyb.vo.LoginUserVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("login")
public class LoginController {
    @Resource
    private LoginService loginService;

    @PostMapping("/user/account")
    public UserInfo selectUserInfoByAccount(@RequestBody @Validated(LoginUserVo.account.class) LoginUserVo vo){
        String account = vo.getAccount();
        boolean isPhoneNo = RegUtils.isPhoneNo(account);
        if(isPhoneNo){
            vo.setIphoneNo(account);
        }
        boolean isEmail = RegUtils.isEmail(account);
        if(isEmail){
            vo.setEmail(account);
        }
        UserInfo userInfo = loginService.selectUserInfoByAccount(vo);
        return userInfo;
    }
}
